package org.zecontech.extraplus.init;

import com.google.common.collect.Maps;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.equipment.ArmorMaterial;
import net.minecraft.world.item.equipment.ArmorType;
import net.minecraft.world.item.equipment.EquipmentAsset;

import java.util.Map;

/**
 * 模组护甲材料
 */
public class ModArmorMaterials {

    public static final ArmorMaterial RUBY_ARMOR = register(
            "ruby_armor",
            15,
            2, 5, 6, 2, 5,
            9,
            SoundEvents.ARMOR_EQUIP_GOLD,
            0.0F,
            0.0F,
            ModItemTagKeys.RUBY_GEM_TAG,
            ModEquipmentAssets.RUBY
    );

    public static final ArmorMaterial AMBER_ARMOR = register(
            "amber_armor",
            15,
            2, 5, 6, 2, 5,
            9,
            SoundEvents.ARMOR_EQUIP_GOLD,
            0.0F,
            0.0F,
            ModItemTagKeys.AMBER_GEM_TAG,
            ModEquipmentAssets.AMBER
    );

    public static final ArmorMaterial EMERALD_ARMOR = register(
            "emerald_armor",
            30,
            4, 8, 8, 4, 10,
            9,
            SoundEvents.ARMOR_EQUIP_GOLD,
            0.0F,
            0.0F,
            ModItemTagKeys.EMERALD_GEM_TAG,
            ModEquipmentAssets.EMERALD
    );
    public static final ArmorMaterial SILVER_ARMOR = register(
            "silver_armor",
            18,
            2, 5, 6, 2, 5,
            20,
            SoundEvents.ARMOR_EQUIP_GOLD,
            0.0F,
            0.0F,
            ModItemTagKeys.SILVER_INGOT_TAG,
            ModEquipmentAssets.SILVER
    );

    /**
     * 注册新的护甲材料
     * @param name 名字
     * @param durability 耐久
     * @param boots 靴子抗性
     * @param leggings 护腿抗性
     * @param chestplate 板甲抗性
     * @param helmet 头盔抗性
     * @param body 身体抗性
     * @param enchantmentValue 附魔值
     * @param equipSound 装备音效
     * @param toughness 韧性
     * @param knockbackResistance 击退抗性
     * @param repairIngredient  修复成分
     * @param assetId 资源ID
     * @return 新的护甲材料
     */
    private static ArmorMaterial register(String name, int durability, int boots, int leggings, int chestplate, int helmet, int body, int enchantmentValue, Holder<SoundEvent> equipSound, float toughness, float knockbackResistance, TagKey<Item> repairIngredient, ResourceKey<EquipmentAsset> assetId) {
        return new ArmorMaterial(durability, makeDefense(boots, leggings, chestplate, helmet, body), enchantmentValue, equipSound, toughness, knockbackResistance, repairIngredient, assetId);
    }

    /**
     * 创建护甲抗性
     * @param boots 靴子
     * @param leggings 护腿
     * @param chestplate 板甲
     * @param helmet 头盔
     * @param body 身体
     * @return 新的护甲抗性
     */
    private static Map<ArmorType, Integer> makeDefense(int boots, int leggings, int chestplate, int helmet, int body) {
        return Maps.newEnumMap(Map.of(ArmorType.BOOTS, boots, ArmorType.LEGGINGS, leggings, ArmorType.CHESTPLATE, chestplate, ArmorType.HELMET, helmet, ArmorType.BODY, body));
    }
}
